﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TimViec.NguoiDung
{
    public partial class TaoHoSoBuoc61 : System.Web.UI.Page
    {
        public int Hosoid { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["NguoiDung"] == null)
            {
                Response.Redirect("/nguoi-dung.html");
                return;

            }
            if (Request.QueryString["hoso"] != "")
            {
                Hosoid = int.Parse(Request.QueryString["hoso"]);
            }
            if (!IsPostBack)
            {

                LoadData(Hosoid);
            }
        }

        private void LoadData(int hosoId)
        {
            var user = BLL.NguoiDung.HoSo.LoadUserByHoSoId(hosoId);
            if (user != null)
            {
                lbName.Text = user.UserName;
                lbSex.Text = user.Sex == true ? "Name" : "Nữ";
                lbNgaySinh.Text = user.Birth.ToString("dd/MM/yyyy");
                //lbQuocTich.Text = user.tbl_DM_Tinh.tbl_DM_QuocGia.Ten;
                lbTTHN.Text = user.RelationShip;

                lbDiaChi.Text = user.DiaChi;
                lbEmail.Text = "<a class='link' href='mailto:" + user.Email + "'>" + " " + user.Email + " " + "</a>";

                imgAvatar.ImageUrl = user.UrlAvatar;
            }

            var hoso = BLL.NguoiDung.HoSo.LoadHoSo(hosoId);
            if (hoso != null)
            {
                lbTieuDe.Text = hoso.TieuDe;

                lbSoNamLamViec.Text = BLL.NguoiDung.HoSo.CountTotalExp(hosoId).ToString();
            }



            rptHocVan.DataSource = BLL.NguoiDung.HoSo.LoadHocVanForView(hosoId);
            rptHocVan.DataBind();

            rptNgoaiNgu.DataSource = BLL.NguoiDung.HoSo.LoadNgoaiNguForView(hosoId);
            rptNgoaiNgu.DataBind();

            rptKiNang.DataSource = BLL.NguoiDung.HoSo.LoadKiNangForView(hosoId);
            rptKiNang.DataBind();

            var muctieu = BLL.NguoiDung.HoSo.LoadMucTieu(hosoId);
            if (muctieu != null)
            {
                lbViTriMongMuon.Text = muctieu.ViTriMongMuon;
                lbMucLuongGanNhat.Text = muctieu.MucLuongGanNhat.ToString();
                lbMucLuongMMTu.Text = muctieu.MucLuongMongMuonTu.ToString();
                lbMucLuongMMDen.Text = muctieu.MucLuongMongMuonTuDen.ToString();

                lbCapBac.Text = muctieu.tbl_DM_CapBacCV.Mota;


                lbLoaiCV.Text = findLoaiCV(muctieu.LoaiCongViecId.Value);

                var par = muctieu.MoiLamUaThich.Split(';');


                var str = "";
                foreach (var s in par)
                {
                    if (s != "")
                        str = BLL.Admin.TinhHelper.Get_TinhId(Int32.Parse(s)).Ten + " ; ";
                }

                lbNoiLam.Text = str;

                lbMucTieu.Text = muctieu.MucTieu;
            }

        }

        protected void LoadId()
        {
            Response.Write("" + Hosoid + "");
        }

        private string findLoaiCV(int id)
        {
            switch (id)
            {
                case 0:
                    return "Toàn thời gian cố định(full-time)";
                case 1:
                    return "Toàn thời gian tạm thời";
                case 2:
                    return "Bán thời gian(part-time)";
                case 3:
                    return "Bán thời gian tạm thời";
                case 4:
                    return "Thực tập(INTERSHIP)";
                case 5:
                    return "Khác";
                default:
                    return "";
            }
        }

        protected void btSave_Click(object sender, EventArgs e)
        {

            Response.Redirect("/nguoi-dung/tu-ho-so.html");
        }

        protected void btSaveAndContinue_Click(object sender, EventArgs e)
        {
            var hosoId = Convert.ToInt32(Request.QueryString["hoso"]);
            BLL.NguoiDung.HoSo.PublicHoSo(hosoId);

            Response.Redirect("/nguoi-dung/"+hosoId+"xem-ho-so.html");
        }
    }
}